<script type="text/javascript">
    $(function(){
        function dataLoaded()
        {
           $(".loading-notification").hide();
        }

        function dataLoading()
        {
           $(".loading-notification").fadeIn();
        }
        $('.new-edit-db').each(function(){
            $('#tab2-content').empty();
           $(this).click(function(){
                var selectedID = '';
                var form_url = '';
                if($(this).attr('rel') == 'new'){
                    selectedID = '';
                    form_url = '<?php echo url_for($sf_context->getModuleName()."/ajaxNewForm") ?>';

                }else{
                    selectedID = $(this).attr('rel');
                    form_url = '<?php echo url_for($sf_context->getModuleName()."/ajaxEditForm") ?>';
                }
                editing = true;
                $('#crud_new').click();
                $.ajax({
                    url: form_url,
                    type: 'POST',
                    data: {id: selectedID},
                    dataType: 'html',
                    beforeSend: function() {
                        dataLoading();
                    },
                    success: function(response) {
                        dataLoaded();
                        $("#tab2-content").empty();
                        $("#tab2-content").html(response);
                    }
                });
           });
        });
    });
</script>
<!-- Main Nav Container -->
<nav id="nav-main">

	<!-- Main Navigation -->
	<ul id="nav-main-navigation">
		<li><a href="<?php echo url_for('@homepage') ?>" title="">Home</a></li>
    <li><a href="<?php echo url_for('contacts/index') ?>">Contacts</a></li>
    <?php if($sf_context->getModuleName() == 'databases'): ?>
		<li><a href="#submenu-1" title="" class="nav-main-subnav">Databases</a><span class="small-notification"><?php echo count($DBs) ?></span></li>
    <?php else: ?>
    <li><a href="<?php echo url_for('databases/index') ?>" title="">Databases</a></li>
    <?php endif; ?>
    <li><a href="<?php echo url_for('datadump/index') ?>">Datadump</a></li>
    <li><a href="<?php echo url_for('emailCampaigns/index') ?>">Email Campaigns</a></li>
    <!--<li><a href="<?php echo url_for('emailPerformance/index') ?>">Email Performance</a></li>-->
    <!--<li><a href="<?php echo url_for('uploadCSV/index') ?>">Upload CSV</a>-->
		<!--<li><a href="#submenu-2" title="">Campaigns</a><span class="small-notification">2</span></li> -->
    <!--<li><a href="#submenu-3" title="" class="nav-main-subnav">Parameters</a></li> -->
    <!--<li><a href="#submenu-4" title="" class="nav-main-subnav">System</a></li> -->
	</ul>
	<!-- /Main Navigation -->

	<!-- User Navigation -->
	<ul id="nav-main-user">
		<li>Welcome <a href="#" title=""><?php echo ucwords($sf_user->getGuardUser()->getFirstName()) ?></a></li>
<!--		<li><a href="#" title="Messages" class="actions"><img alt="Messages" src="/images/icons/icon_user_message.png"></a></li>
		<li><a href="#" title="Settings" class="actions"><img alt="Settings" src="/images/icons/icon_user_settings.png"></a></li>-->
		<li><a href="<?php echo url_for('sf_guard_signout') ?>" title="Logout" class="actions"><img alt="Logout" src="/images/icons/icon_user_logout.png"></a></li>
	</ul>
	<!-- /User Navigation -->

</nav>
<!-- /Main Nav Container -->

<!-- Sub Nav Container -->
<nav id="nav-sub">

	<!-- Sub Nav Block #submenu-1 -->
	<div id="submenu-1" class="submenu">

		<!-- Standard Sub Nav List Style -->
		<!-- Use class .menu-fit to indent list under 1st main menu item -->
		<ul class="standard-list menu-fit scroll-db">
			<li class="standard-list-header"><h2>List of databases</h2></li>
			<?php foreach($DBs as $db) : ?>
                <li><a href="#" rel="<?php echo $db->id ?>" class="new-edit-db"><?php echo $db->name; ?> - <?php echo $db->table_source;?></a></li>
              <?php endforeach; ?>
		</ul>
		<!-- /Standard Sub Nav List Style -->
		<ul class="standard-list">
			<li class="standard-list-header"><h2><a href="#" rel="new" class="new-edit-db">Add new</a></h2></li>
		</ul>
	</div>
	<!-- /Sub Nav Block #submenu-1 -->

	<!-- Sub Nav Block #submenu-2 -->
	<div id="submenu-2" class="submenu">
		<ul class="standard-list menu-fit">
			<li class="standard-list-header"><h2>Some Links</h2></li>
			<li><a href="#">Envato</a></li>
			<li><a href="#">ActiveDen</a></li>
			<li><a href="#">AudioJungle</a></li>
			<li><a href="#">ThemeForest</a></li>
			<li><a href="#">VideoHive</a></li>
			<li><a href="#">GraphicRiver</a></li>
			<li><a href="#">3DOcean</a></li>
			<li><a href="#">CodeCanyon</a></li>
			<li><a href="#">Creattica</a></li>
		</ul>

		<!-- Box Sub Nav List Style -->
		<ul class="box-list">
			<li class="box-list-header"><h2>Useful Links</h2></li>
			<li><a href="#">Appstorm</a></li>
			<li><a href="#">Mac.Appstorm</a></li>
			<li><a href="#">Web.Appstorm</a></li>
			<li><a href="#">iPhone.Appstorm</a></li>
			<li><a href="#">TheNetsetter</a></li>

		</ul>
		<!-- /Box Sub Nav List Style -->

		<ul class="box-list header-fit">
			<li><a href="#">FreelanceSwitch</a></li>
			<li><a href="#">WorkAwesome</a></li>
			<li><a href="#">DrinkAwesome</a></li>
			<li><a href="#">LiveAwesome</a></li>
			<li><a href="#">SleepAwesome</a></li>
		</ul>
		<ul class="box-list header-fit">
			<li><a href="#">Psdtuts+</a></li>
			<li><a href="#">Nettuts+</a></li>
			<li><a href="#">Vectortuts+</a></li>
			<li><a href="#">Audiotuts+</a></li>
			<li><a href="#">Aetuts+</a></li>
		</ul>

		<!-- You can also use articles in submenu, they will automatically align to the right or use class .perex to align left  -->
		<article>
			<h2>Header H2</h2>
			<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse et dignissim metus. Maecenas id augue ac metus tempus aliquam.</p>
		</article>
	</div>
	<!-- /Sub Nav Block #submenu-2 -->

	<!-- Sub Nav Block #submenu-3 -->
	<div id="submenu-3" class="submenu">

		<!-- Box Sub Nav List Style -->
		<ul class="standard-list menu-fit">
			<li class="box-list-header"><h2>System Parameters</h2></li>
			<li><a href="<?php echo url_for('country/index') ?>">Country, Region, Department & City</a></li>
			<li><a href="#">Enseigne</a></li>
			<li><a href="#">Groups</a></li>
			<li><a href="#">Store Group & Store</a></li>
			<li><a href="#">Suplier & Brand</a></li>
		</ul>
		<!-- /Box Sub Nav List Style -->

		<ul class="standard-list">
			<li class="box-list-header"><h2>System Lookup</h2></li>
			<li><a href="#">Store Type</a></li>
			<li><a href="#">Product Type</a></li>
			<li><a href="#">Nomenclature</a></li>
			<li><a href="#">Theme Catalogue</a></li>
			<li><a href="#">Promotion Type</a></li>
		</ul>

		<ul class="box-list">
			<li class="box-list-header"><h2>Online Users</h2></li>
			<li><a href="#">Psdtuts+</a></li>
			<li><a href="#">Nettuts+</a></li>
			<li><a href="#">Vectortuts+</a></li>
			<li><a href="#">Audiotuts+</a></li>
			<li><a href="#">Aetuts+</a></li>
		</ul>

		<!-- You can also use articles in submenu, they will automatically align to the right or use class .perex to align left  -->
		<article>
			<h2>Latest Updates</h2>
			<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse et dignissim metus. Maecenas id augue ac metus tempus aliquam.</p>
			<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse et dignissim metus. Maecenas id augue ac metus tempus aliquam.</p>
		</article>

	</div>
	<!-- /Sub Nav Block #submenu-3 -->

	<!-- Sub Nav Block #submenu-4 -->
	<div id="submenu-4" class="submenu">
		<!-- Box Sub Nav List Style -->
		<ul class="standard-list menu-fit">
			<li class="box-list-header"><h2>Access Rights</h2></li>
			<li><a href="<?php echo url_for('user/index')?>">Users</a></li>
			<li><a href="<?php echo url_for('brand/index')?>">Brand</a></li>
			<li><a href="<?php echo url_for('brandType/index')?>">Brand Type</a></li>
			<li><a href="<?php echo url_for('city/index')?>">City</a></li>
			<li><a href="<?php echo url_for('country/index')?>">Country</a></li>
			<li><a href="<?php echo url_for('department/index')?>">Department</a></li>
			<li><a href="<?php echo url_for('enseigne/index')?>">Enseigne</a></li>
			<li><a href="<?php echo url_for('groups/index')?>">Groups</a></li>
			<li><a href="<?php echo url_for('nomenclature/index')?>">Nomenclature</a></li>
			<li><a href="<?php echo url_for('productType/index')?>">Product Type</a></li>
			<li><a href="<?php echo url_for('promotionType/index')?>">Promotion Type</a></li>
			<li><a href="<?php echo url_for('region/index')?>">Region</a></li>
			<li><a href="<?php echo url_for('store/index')?>">Store</a></li>
			<li><a href="<?php echo url_for('storeGroup/index')?>">Store Group</a></li>
			<li><a href="<?php echo url_for('storeType/index')?>">Store Type</a></li>
			<li><a href="<?php echo url_for('supplier/index')?>">Supplier</a></li>
			<li><a href="<?php echo url_for('themeCatalogue/index')?>">Theme Catalogue</a></li>
		</ul>
		<!-- /Box Sub Nav List Style -->

		<!-- Box Sub Nav List Style -->
		<ul class="standard-list">
			<li><a href="<?php echo url_for('promotionType/index')?>">Promotion Type</a></li>
			<li><a href="<?php echo url_for('region/index')?>">Region</a></li>
			<li><a href="<?php echo url_for('store/index')?>">Store</a></li>
			<li><a href="<?php echo url_for('storeGroup/index')?>">Store Group</a></li>
			<li><a href="<?php echo url_for('storeType/index')?>">Store Type</a></li>
			<li><a href="<?php echo url_for('supplier/index')?>">Supplier</a></li>
			<li><a href="<?php echo url_for('themeCatalogue/index')?>">Theme Catalogue</a></li>
		</ul>
		<!-- /Box Sub Nav List Style -->

		<ul class="box-list">
			<li class="box-list-header"><h2>Online Users</h2></li>
			<li><a href="#">Appstorm</a></li>
			<li><a href="#">Mac.Appstorm</a></li>
			<li><a href="#">Web.Appstorm</a></li>
			<li><a href="#">iPhone.Appstorm</a></li>
			<li><a href="#">TheNetsetter</a></li>

		</ul>
		<ul class="box-list header-fit">
			<li><a href="#">Psdtuts+</a></li>
			<li><a href="#">Nettuts+</a></li>
			<li><a href="#">Vectortuts+</a></li>
			<li><a href="#">Audiotuts+</a></li>
			<li><a href="#">Aetuts+</a></li>
		</ul>

		<!-- You can also use articles in submenu, they will automatically align to the right or use class .perex to align left  -->
		<article>
			<h2>Latest System Updates</h2>
			<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse et dignissim metus. Maecenas id augue ac metus tempus aliquam.</p>
			<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse et dignissim metus. Maecenas id augue ac metus tempus aliquam.</p>
		</article>
	</div>
	<!-- /Sub Nav Block #submenu-4 -->

</nav>